/**
 * Copyright (C) 2011 The Android Open Source Project 
 * Emial : guoyil199@163.com
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at 
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0 
 * 
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 * See the License for the specific language governing permissions and 
 * limitations under the License. 
 */
package com.wifibrowser.wifi.util;

import java.util.ArrayList;
import java.util.Arrays;

import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.text.TextUtils;

/**
 * @author Administrator
 * @Email guoyil199@163.com
 * @version V1.0
 * @Date 2016年2月17日 下午4:27:52
 * @Title <B>todo</B>
 * 
 *        <pre>
 * todo
 * </pre>
 */

public class WifiUtil {

	public static final String CMCC = "中国移动免费热点";
	public static final String CHINA_UNICOM = "中国联通免费热点";
	public static final String CHINANET = "中国电信免费热点";
	public final static String ENABLE_SHOW_CHANNEL = "show_channel";
	public final static String ENABLE_SHOW_RSSI = "show_rssi";
	
	public final static String AUTO_LOGIN_KEY = "enable_auto_login";
	public final static String ENABLE_NOTIFICATION_KEY = "enable_notify";
	public static final String REBOOT_START = "reboot";

	private final static ArrayList<Integer> channelsFrequency = new ArrayList<Integer>(Arrays.asList(0, 2412, 2417, 2422, 2427, 2432, 2437, 2442, 2447, 2452, 2457, 2462, 2467, 2472, 2484));

	public static Integer getFrequencyFromChannel(int channel) {
		return channelsFrequency.get(channel);
	}

	public static int getChannelFromFrequency(int frequency) {
		return channelsFrequency.indexOf(Integer.valueOf(frequency));
	}

	public static String getOperatorWifiName(String ssid) {
		if (TextUtils.equals(ssid, "CMCC")) {
			return CMCC;
		} else if (TextUtils.equals(ssid, "ChinaNet")) {
			return CHINANET;
		} else if (TextUtils.equals(ssid, "ChinaUnicom")) {
			return CHINA_UNICOM;
		} else {
			return ssid;
		}
	}

	public static boolean getEnableShowRssi(Context context) {
		SharedPreferences sPref = PreferenceManager.getDefaultSharedPreferences(context);
		return sPref.getBoolean(ENABLE_SHOW_RSSI, false);
	}

	public static boolean getEnableShowChannel(Context context) {
		SharedPreferences sPref = PreferenceManager.getDefaultSharedPreferences(context);
		return sPref.getBoolean(ENABLE_SHOW_CHANNEL, false);
	}

	public static boolean getEnableAutoLogin(Context context) {
		SharedPreferences sPref = PreferenceManager.getDefaultSharedPreferences(context);
		return sPref.getBoolean(AUTO_LOGIN_KEY, true);
	}

}
